<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>订单打印详情</title>
<link href="__TPL_CSS__/print1.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="print-page" id="printDiv1">
  <div class="orderprint">
	  {if $qrshow===1}
	  <div class="qrcode">
	  	<img src="{$qrcode_url}"/>
		<div>{$print.deal_qrcode_tips}</div>
	  </div>
	  {/if}
      <div class="top">
		<div class="full-title">{$print.title}</div>
		<div class="full-title2"><u>&nbsp;&nbsp;&nbsp;销售出货单&nbsp;&nbsp;&nbsp;</u></div>
		<div class="full-title3">联系电话：{$print.phone}</div>
	</div>
      <table class="buyer-info">
        <tr>
          <td height="22" class="w240">订单号：<span class="form-control-static">{$T.number} </span></td>          
        </tr>
        <tr>
          <td height="22">客户：{if $T.customer.company == ''}{$T.customer.name}{else/}{$T.customer.company}{/if}</td>
          <td height="22" align="right"><span class="form-control-static">{$T.create_time|date="Y年m月d日"}</span></td>
        </tr>
      </table>
      <table class="order-info">
        <thead>
          <tr>
            <th width="5%">编号</th>
            <th width="18%">品名</th>
            <th width="4%">色号</th>
            <th width="5%">颜色</th>
            <th width="3%"></th>
            <th width="4%">1</th>
            <th width="4%">2</th>
            <th width="4%">3</th>
            <th width="4%">4</th>
            <th width="4%">5</th>
            <th width="4%">6</th>
            <th width="4%">7</th>
            <th width="4%">8</th>
			<th width="4%">单位</th>
            <th width="5%">数量</th>
			<th width="4%">- KG</th>
            <th width="5%">单价</th>
            <th width="8%">金额</th>
          </tr>
        </thead>
        <tbody>
           {volist name="Tinfo" id="v"}
            <tr>
                <td>{$v.number}</td>
                <td style="text-align:left; padding:0px 5px;">{$v.name}</td>
                <td>{$v.color}</td>
                <td>{$v.colorname}</td>
                <td style="background:#{$v.colorval}"></td>
                {php}
                foreach($v['weight'] as $val){
                   echo '<td>'.$val.'</td>';
                }
                {/php}
				<td>{$v.unit}</td>
                <td>{$v.count}</td>
				<td>{if $T['reduce'] > 0}-{$v.reduce}{/if}</td>
                <td>{$v.unitprice|price_one}</td>
                <td class="right">{$v.total|price_one}</td>
            </tr>
            {/volist}
            {php}
            $len=10-count($Tinfo);
            if($len>0){
              for($i=0;$i<=$len;$i++){
                echo '<tr><td>&nbsp;</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
              }
            }
            {/php}
        </tbody>
        <tfoot>
          <tr>
            <td colspan="7" style="text-align:left; padding-left:5px;">总金额（大写）RMB ：<span class="cny">{$T.total|cny}</span></td>
            <td colspan="11" style="text-align:right; padding-right:5px;">
				共 {$T.volume} 匹 &nbsp;&nbsp;&nbsp;&nbsp;
				数量：{$T.count}&nbsp;&nbsp;
				{if $T['reduce'] > 0}优惠：-{$T.reduce} KG&nbsp;&nbsp;{/if}
				{if $T['freight'] > 0}运费：&yen; {$T.freight|price_one}&nbsp;&nbsp;{/if}
				{if $T['coupon'] > 0 && $T['paytype']=='公账开票'}税费：&yen; {$T.coupon|price_one}&nbsp;&nbsp;{/if}
				{if $T['coupon'] > 0 && $T['paytype']!='公账开票'}差价：&yen; {$T.coupon|price_one}&nbsp;&nbsp;{/if}
				{if $T['coupon'] < 0}优惠：&yen; {$T.coupon|price_one}&nbsp;&nbsp;{/if}
				总计：&yen; {$T.total|price}
			</td>
          </tr>
          <tr class="remark">
            <td colspan="18" style="text-align:left;">{$print.deal_remark|raw}</td>
          </tr>
        </tfoot>
      </table>
    <div class="explain">
  </div>
  </div>
</div>


<div class="print_but">
	<a http_printer=''>打印订单</a>
</div>

<script src="__JS__/jquery.1.8.3.js"></script>
<script src="/static/component/layui/layui.js"></script>
<script>
	
	$(document).ready(function(){
		layui.use('layer', function(){
			var layer = layui.layer;
		});
		
		//打印销售单
		$("[http_printer]").click(function(){  
			var print_url = 'http://{$print["ip"]}:{$print["port"]}/';
			var msg_post = '{$print_data|raw}';
			
			var msg = '{"method":"getprinterlist","token":"","taskid":""}';	
			jQuery.support.cors = true;         //写到$.ajax $.get $.post 前面 解决 jQuery.Ajax IE8,9 无效（CORS跨域）						
			 
			$.get(
				print_url+'?time='+new Date().getTime(),
				function (data, status, jqxhr) {
					jQuery.support.cors = true;         //写到$.ajax $.get $.post 前面 解决 jQuery.Ajax IE8,9 无效（CORS跨域）								
					
					$.ajax({
						async : false, //循环打印时,　async 必须设置为 false，则所有的请求均为同步请求，在没有返回值之前，同步请求将锁住浏览器，用户其它操作必须等待请求完成才可以执行。
						url : print_url,
						type : "POST",
						contentType: "application/x-www-form-urlencoded",  
						dataType : "json", //设置为 json 格式
						xhrFields: {withCredentials: false},
						crossDomain: true, 
						data : msg_post,
						beforeSend: function (XMLHttpRequest) {
							 // beforeSend 函数里 不允许添加任何 东西	
				             //XMLHttpRequest.setRequestHeader("token", 'abcd1234'); //不允许 使用jQuery发送AJAX请求时在header中添加Token
				        },
						success: function(data){
							console.log(JSON.stringify(data));			
							if(data.status=="ok"){
								// alert("打印成功:"+data.data);				
							}else{
								// alert("打印失败:"+data.data);
							}
						},
						error: function(data){
							//console.log(status, response);
							console.log(JSON.stringify(data));
							alert("连接HttpPrinter失败:"+JSON.stringify(data));
						}
					});	  
					
			}).fail(function () {
				alert('链接失败');
				var index = layer.confirm('连接HttpPrinter失败？', {
				  btn: ['下载','启动试试','关闭'] //按钮
				}, function(){
				  //弹出下载链接
				  window.open('http://www.httpprinter.com/httpprinter.html',"_blank"); //转到一个新的tab
				  //关闭提示框		
				  layer.close(index); 
				}
				, function(){
				layer.close(index); 
				  //启动本地exe文件				  
				  window.open('HttpPrinter://hello',"_blank"); //转到一个新的tab
				  //关闭提示框		
				  layer.close(index); 
				}
				, function(){
					//关闭提示框		
					layer.close(index); 				  
				}
				);
			});
		  });
	})
</script>
</body>
</html>